package com.senbai.springlearning.threadlearn.thread;

import com.senbai.springlearning.threadlearn.bean.OrderQuery;
import com.senbai.springlearning.threadlearn.service.QueryService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;

public class QueryInvoice  implements Callable<Map<String,Object>> {

    public String orderNo;

    public CountDownLatch cdl;

    @Autowired
    QueryService queryService;

    public QueryInvoice(String orderNo,CountDownLatch cdl) {
        this.orderNo = orderNo;
        this.cdl = cdl;
    }

    @Override
    public Map<String,Object> call() throws Exception{
        Map<String,Object> queryResult = new HashMap<>();
        cdl.await();
        OrderQuery orderQuery = new OrderQuery();
        String id = UUID.randomUUID().toString();
        CompletableFuture<Map<String,Object>> cf = new CompletableFuture<>();
        orderQuery.setId(id);
        orderQuery.setOrderNo(orderNo);
        orderQuery.setCf(cf);
        queryService.addToQuery(orderQuery);
        System.out.println(this.hashCode()+"开始查询订单"+orderNo);
        return queryResult;
    }
}
